/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servidor;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author rowsinner
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            Server s = new Server();
            //usamos un wrapper para preparar la instancia para exportarla
            IServer stub = (IServer) UnicastRemoteObject.exportObject(s, 0); 
            //creamos una instancia de Registry la cual escucha en el puerto indicado por llamadas
            Registry r = LocateRegistry.createRegistry(1099);
            //ponemos la instancia wrappeada del Server en el registro para enviarla cuando la pidan
            r.rebind("IServer", stub);
            String c;
            try {
                c = br.readLine();
                while(!c.equals("STOP")){
                    c = br.readLine();
                }
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (RemoteException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
